import { Controller } from "../../mvc/core/Controller";
import { TestPVPInterfacePanel } from "../view/crossPVP/TestPVPInterfacePanel";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { SCrossCountryInfo } from "../../../Message/Game/SCrossCountryInfo";
import { EPassType } from "../../../Message/Game/EPassType";
type int = number;
//class CrossPVPController
    
    export  class CrossPVPController extends Controller
    {
       

        public get testPanel(): TestPVPInterfacePanel
        {
            if (!this._testPanel) 
            {
                this._testPanel = new TestPVPInterfacePanel();
            }
            return this._testPanel;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.CrossPVP_openTestInterface, this.doOpenTestPanel);
            Dispatcher.addEventListener(EventName.CrossPVP_getServerList, this.doGetCrossCountryServerList);
            Dispatcher.addEventListener(EventName.CrossPVP_getServerListSuccess, this.onGetCrossCountryServerListSuccess);
            Dispatcher.addEventListener(EventName.CrossPVP_enterCrossCountry, this.doEnterCrossCountry);
            Dispatcher.addEventListener(EventName.CrossPVP_leaveCrossCountry, this.doLeaveCrossCountry);
            return;
        }

        /* internal  */doOpenTestPanel(arg1: DataEvent): void
        {
            this.testPanel.show();
            return;
        }

        /* internal  */doGetCrossCountryServerList(arg1: DataEvent): void
        {
            GameProxy.country.getCrossCountryList();
            return;
        }

        /* internal  */onGetCrossCountryServerListSuccess(arg1: DataEvent): void
        {
            if (this._testPanel && !this._testPanel.isHide) 
            {
                this.testPanel.updateCountryList(arg1.data as Array<any>);
            }
            return;
        }

        /* internal  */doEnterCrossCountry(arg1: DataEvent): void
        {
            var loc1=arg1.data["countryKey"] as SCrossCountryInfo;
            var loc2=loc1.serverKey;
            var loc3=arg1.data["pointType"] as int;
            GameProxy.sceneProxy.pass(EPassType.convert(EPassType._EPassTypeCrossCountry), loc2.proxyId, loc2.serverId, loc3);
            return;
        }

        /* internal  */doLeaveCrossCountry(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.sceneProxy.pass(EPassType.convert(EPassType._EPassTypeCrossCountry), 0, 0, loc1);
            return;
        }

        private /* var */_testPanel: TestPVPInterfacePanel;
    }
